import React from "react";
import {
  Link,
  Routes,
  Route,
  useSearchParams,
  useLocation,
} from "react-router-dom";

const Home = () => <div>这是首页</div>;
const About = () => <div>这是关于页</div>;
const Detail = () => {
  // 如果要获取到query的信息，那么可以直接使用useSearchParams
  const [searchParams] = useSearchParams();
  console.log(searchParams.get("a"));

  const location = useLocation();
  console.log(location);

  return <div>这是详情页</div>;
};

const App = () => {
  return (
    <div>
      <h2>router-v6-query传参</h2>
      <ul>
        <li>
          <Link to="/">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          {/* <Link to="/detail?a=3&b=4&c=5">详情页</Link> */}
          {/* Link里面的state和to属性分开了 */}
          <Link
            to={{
              pathname: "/detail",
              search: "?a=3&b=4&c=5",
            }}
            state={{
              x: 10,
              y: 20,
            }}
          >
            详情页
          </Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/" element={<Home></Home>}></Route>
        <Route path="/about" element={<About />}></Route>
        <Route path="/detail" element={<Detail />}></Route>
      </Routes>
    </div>
  );
};

export default App;
